package player.ui;

import java.awt.Insets;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseWheelEvent;

import javax.swing.JFrame;
import javax.swing.JWindow;


public class PlayerFrame extends JWindow{
	private static final long serialVersionUID = -8303043308519333372L;
	static JFrame mf=new JFrame();
	PlayerFrame frame;
	VideoPanel panel;
	Insets gap=new Insets(0,0,0,0);
	Thread sizeThread;
	boolean large=true;
	Rectangle recDst;
	public PlayerFrame(){
		super(mf);
		frame=this;
		mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mf.setBounds(-50, -50, 0, 0);
		mf.setVisible(true);
		

		panel=new VideoPanel(frame);
		setContentPane(panel);
		
		
		
	}

	public void changeSize(MouseWheelEvent e,float rate){
		int i=e.getWheelRotation();
		int t=(int) (getWidth()*0.13f);
		if(i>0){
			t=(0-t);
		}
		int newW=getWidth()+t;
		float rx=(float)e.getX()/getWidth();
		int w1=(int) (newW*rx);
		int w2=newW-w1;
		
		int newH=(int) (newW/rate);
		float ry=(float)e.getY()/getHeight();
		int h1=(int) (newH*ry);
		int h2=newH-h1;
		
		Point mousePoint = MouseInfo.getPointerInfo().getLocation();
		int ex=mousePoint.x;
		int ey=mousePoint.y;
		
		setBounds(getOutSize(w1,w2,h1,h2,ex,ey));
	}
	
	void setDstBounds(Rectangle r1){
		recDst=r1;
		sizeThread.interrupt();
	}
	
	Rectangle getOutSize(int w1,int w2,int h1,int h2,int xe,int ye){
		Rectangle rec=new Rectangle();
		int xf=xe-(gap.left+w1);
		int wf=(w1+w2)+(gap.left+gap.right);
		int yf=ye-(gap.top+h1);
		int hf=(h1+h2)+(gap.top+gap.bottom);
		rec=new Rectangle(xf, yf, wf, hf);
		return rec;
	}
}
